﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BookExchange.Business;
using BookExchange.ODataService;

namespace BookExchange
{
    public partial class ViewRequest : System.Web.UI.Page
    {
        RequestBusiness requestBus;

        public ViewRequest()
        {
            this.requestBus = new RequestBusiness();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                PopulateControls();
            }
        }
        private void PopulateControls()
        {
            string reqID = Request.QueryString["id"];
            ODataService.Request data = null;// requestBus.DB.Requests.Where(c => c.MemberCode == Convert.ToInt32(reqID)).SingleOrDefault();
            if (data != null)
            {
                repBook.DataSource = data;
                repBook.DataBind();
            }
        }

        public string ShowData(object input, string columnName)
        {
            ODataService.Request data = input as ODataService.Request;
            // bài viết chưa checkout hoac uer checkout cung la user hien tai =>> co the sua bai viet
            switch (columnName)
            {
                case "Finish":
                    string s = data.BookName;
                    if (data.Finished == 1)
                        s += " (Đã bán)";
                    return s;
                case "Category":
                    Category cat = null;//bus.DB.Categories.Where(c => c.CategoryCode == data.CategoryCode).SingleOrDefault();
                    return cat.Description;
                case "Image":
                    string img = null;//bus.DB.Images.Where(c => c.RequestCode == data.RequestCode).FirstOrDefault();
                    return string.Empty;
                //return "url";
                case "Discount":
                    double discount = 100 - ((double)data.Price2 / (double)data.Price1) * 100;
                    return (int)discount + "%";
                //return "30%";
                default: return string.Empty;
            }
        }
    }
}